// BlogCommentService.java
package net.web.service;

import net.web.dao.BlogCommentDao;
import net.web.dao.BlogDao;
import net.web.entity.BlogComment;
import net.web.entity.MessageNotification;
import net.web.service.MessageNotificationService;

import java.util.List;

public class BlogCommentService {
    private BlogCommentDao commentDao = new BlogCommentDao();
    private BlogDao blogDao = new BlogDao();
    private MessageNotificationService messageNotificationService = new MessageNotificationService();

    // 在 BlogCommentService 的 addComment 方法中添加消息通知逻辑
    public boolean addComment(BlogComment comment) {
        boolean result = commentDao.insert(comment);
        if (result) {
            Integer blogAuthorId = blogDao.getAuthorIdByBlogId(comment.getBlogId());
            if (blogAuthorId != null && blogAuthorId != comment.getAuthorId()) {
                MessageNotification notification = new MessageNotification();
                notification.setRecipientId(blogAuthorId);
                notification.setSenderId(comment.getAuthorId());
                notification.setBlogId(comment.getBlogId());
                notification.setMessageType("comment");
                messageNotificationService.sendNotification(notification);
            }
        }
        return result;
    }

    public List<BlogComment> getCommentsByBlogId(int blogId) {
        return commentDao.getCommentsByBlogId((long) blogId);
    }
}